//
//  HotelViewController.m
//  MeterMart
//
//  Created by ENERGY on 2018/11/3.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "HotelViewController.h"
#import "HotelTableViewCell.h"
#import "SDCycleScrollView.h"
#import "CDZStarsControl.h"
#import "FeatureCollectionViewCell.h"
#import "ComboViewController.h"
#import "ShareView.h"
#import "CalendarHomeViewController.h"
#import "PhoneRegisterViewController.h"
#import "CommonViewController.h"
#import "WeChatLoginViewController.h"

@interface HotelViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, SDCycleScrollViewDelegate, CDZStarsControlDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong)UILabel * titleLab;
@property (nonatomic, strong)UIButton * shareBtn;
@property (nonatomic, strong)CDZStarsControl *starsControl;//星级评价
@property (nonatomic, strong)UILabel * starNumLab;//几星
@property (nonatomic, strong)UICollectionView * collectionView;
@property (nonatomic, strong)UILabel * locationLab;//大概方向
@property (nonatomic, strong)UILabel * addressLab;//详细地址
@property (nonatomic, strong)UIButton * phoneBtn;//电话
@property (nonatomic, strong)UILabel * perSpendLab;//人均
@property (nonatomic, strong)NSMutableArray * cellArr;
@property (nonatomic, strong)NSDictionary * model;
@property (nonatomic, strong)NSMutableArray * itemArr;
@property (nonatomic, strong)NSString * phoneNum;
@property (nonatomic, strong)ShareView * shareView;//分享页面
@property (nonatomic, strong)UIView * rectangleView;//分割线
@property (nonatomic, strong)UILabel * inHotelLab;//入店
@property (nonatomic, strong)UILabel * outHotelLab;//离店
@property (nonatomic, strong)UILabel * totalDayLab;//共计几晚
@property (nonatomic, strong)CalendarHomeViewController *chvc;//日历
- (void)weChatShareURL:(int)scene;//分享
//酒店日历
@property (nonatomic, strong)NSMutableArray * dataArray;
@property (nonatomic, strong)UIView * mainView;
@property (nonatomic, strong)UILabel * specificLab;//具体时间
@property (nonatomic, strong)NSString * todayString;
@property (nonatomic, strong)NSString * nextdayString;
@property (nonatomic, strong)NSString * liveDaysString;//住了几天

@property (nonatomic, strong)NSString * codeString;//微信登录回调code
@property (nonatomic, strong)NSString * ifPay;//1为没交会员钱，0为已交会员钱
@property (nonatomic, strong)NSString * shareURL;//分享地址
@property (nonatomic, strong)UIButton * dataBGView;//日历背景
@end

@implementation HotelViewController(networking)
//列表数据
- (void)getProdeceData{
    NSDictionary * dic = @{
                           @"typeid_goods":self.prodeceID,
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"listiosApi/hotel_index" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"sign"] isEqualToString:@"1"]) {
            [self.cellArr removeAllObjects];
            [self.cellArr addObjectsFromArray:responseObject[@"list"][@"goodsinfo"]];
            self.model = responseObject[@"list"][@"info"];
            self.shareURL = responseObject[@"list"][@"url"];
            [self.tableView reloadData];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

- (void)getRoomCount{
    NSDictionary * dic = @{
                           @"start":self.inHotelLab.text,
                           @"end":self.outHotelLab.text,
                           @"typeid_goods":self.prodeceID,
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"listApi/findroomcount" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"sign"] isEqualToString:@"1"]) {
            [self.cellArr removeAllObjects];
            [self.cellArr addObjectsFromArray:responseObject[@"list"][@"goodsinfo"]];
            [self.tableView reloadData];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}
@end
@implementation HotelViewController
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self.view addSubview:self.tableView];
    if ([self.typeID isEqualToString:@"2"]) {
        self.dataBGView.hidden = NO;
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.dataBGView.bottom);
    }else{
        self.dataBGView.hidden = YES;
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.rectangleView.bottom);
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //分享
    int shareBtnW = 30/WIDTH_6_SCALE;
    self.shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, shareBtnW, shareBtnW)];
    [self.shareBtn setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
    [self.shareBtn addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.shareBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.liveDaysString = @"1";
    if (![WXApi isWXAppInstalled]) {
        self.shareBtn.hidden = YES;
    }
    [self getProdeceData];//网络接口
}
#pragma mark - init
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.phoneNum = model[@"mobile"];
    self.cycleScrollView.imageURLStringsGroup = model[@"images"];
    self.starNumLab.text = [NSString stringWithFormat:@"%@分", model[@"score"]];
    self.starsControl.score = [model[@"score"] floatValue];//星星亮多少
    self.addressLab.text = model[@"address"];
    self.locationLab.text = model[@"distance_hints"];
    self.perSpendLab.text = [NSString stringWithFormat:@"人均￥%@", model[@"consumption"]];
    self.titleLab.text = model[@"name"];
    self.navigationItem.title = model[@"name"];
    [self.itemArr removeAllObjects];
    [self.itemArr addObjectsFromArray:model[@"introduce"]];
    [self.collectionView reloadData];
}
- (ShareView *)shareView{
    if (!_shareView) {
        __weak typeof (self)weakSelf = self;
        _shareView = [[ShareView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT)];
        _shareView.friendBtnClickBlock = ^{
            [weakSelf wxShare:0];
        };
        _shareView.circleBtnClickBlock = ^{
            [weakSelf wxShare:1];
        };
    }return _shareView;
}
- (NSMutableArray *)cellArr{
    if (!_cellArr) {
        _cellArr = @[].mutableCopy;
    }return _cellArr;
}
- (NSMutableArray *)itemArr{
    if (!_itemArr) {
        _itemArr = @[].mutableCopy;
    }return _itemArr;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT - NAVI_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = 121/WIDTH_6_SCALE;
        [_tableView registerClass:[HotelTableViewCell class] forCellReuseIdentifier:NSStringFromClass([HotelTableViewCell class])];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        self.cycleScrollView = [[SDCycleScrollView alloc] init];
        if (Is_Iphone_X) {
            _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 278/WIDTH_6_SCALE + 24);
            self.cycleScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 230/WIDTH_6_SCALE + 24);
        }else{
            _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 278/WIDTH_6_SCALE);
            self.cycleScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 230/WIDTH_6_SCALE);
        }
        _headerView.backgroundColor = [UIColor whiteColor];
        //轮播图
        self.cycleScrollView.placeholderImage = [UIImage imageNamed:@"YimiPlaceHolder"];
        self.cycleScrollView.delegate = self;
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        self.cycleScrollView.currentPageDotColor = [UIColor whiteColor];
        self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        [_headerView addSubview:self.cycleScrollView];
        //标题
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, self.cycleScrollView.bottom +25/WIDTH_6_SCALE, SCREEN_WIDTH - 36/WIDTH_6_SCALE, 18/WIDTH_6_SCALE)];
        [self label:self.titleLab withFont:DEF_FontSize_15 withText:@"---" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        //星星
        [_headerView addSubview:self.starsControl];
        //几星
        self.starNumLab = [[UILabel alloc] initWithFrame:CGRectMake(self.starsControl.right + 10/WIDTH_6_SCALE, 0, 50/WIDTH_6_SCALE, self.starsControl.height)];
        self.starNumLab.centerY = self.starsControl.centerY;
        [self label:self.starNumLab withFont:DEF_FontSize_12 withText:@"5分" withTextColor:getColor(@"ffaf9a") withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        //人均
        self.perSpendLab = [[UILabel alloc] initWithFrame:CGRectMake(self.starNumLab.right + 30/WIDTH_6_SCALE, self.starNumLab.top, 100/WIDTH_6_SCALE, self.starNumLab.height)];
        [self label:self.perSpendLab withFont:DEF_FontSize_12 withText:@"" withTextColor:getColor(textGrayColor) withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        //collectionView
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
        layout.estimatedItemSize = CGSizeMake(60/WIDTH_6_SCALE, 30/WIDTH_6_SCALE);// layout约束这边必须要用estimatedItemSize才能实现自适应,使用itemSzie无效
        layout.scrollDirection =  UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset = UIEdgeInsetsMake(0/WIDTH_6_SCALE, 12/WIDTH_6_SCALE, 0/WIDTH_6_SCALE, 0/WIDTH_6_SCALE);
        // 设置 最小列间距
        layout. minimumInteritemSpacing  = 14/WIDTH_6_SCALE;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.starsControl.bottom + 5/WIDTH_6_SCALE, SCREEN_WIDTH, 34/WIDTH_6_SCALE) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[FeatureCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([FeatureCollectionViewCell class])];
        [_headerView addSubview:_collectionView];
        //分割线
        UIView * rectangleView = [[UIView alloc] initWithFrame:CGRectMake(0, self.starsControl.bottom + 46/WIDTH_6_SCALE, SCREEN_WIDTH, 73/WIDTH_6_SCALE)];
        rectangleView.backgroundColor = [UIColor whiteColor];
        [self setBorderWithView:rectangleView top:YES left:NO bottom:YES right:NO borderColor:getColor(@"f7f7f7") borderWidth:1];
        self.rectangleView = rectangleView;
        [_headerView addSubview:rectangleView];
        //位置图标
        UIImageView * locationImg = [[UIImageView alloc] init];
        locationImg.image = [UIImage imageNamed:@"location"];
        [rectangleView addSubview:locationImg];
        //详细地址
        self.addressLab = [[UILabel alloc] init];
        [self label:self.addressLab withFont:DEF_FontSize_12 withText:@"---" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:rectangleView];
        self.addressLab.lineBreakMode = 0;
        self.addressLab.numberOfLines = 0;
        //大概方向
        self.locationLab = [[UILabel alloc] init];
        [self label:self.locationLab withFont:DEF_FontSize_11 withText:@"---" withTextColor:getColor(@"a5a5a5") withTextAlignment:NSTextAlignmentLeft withView:rectangleView];
        self.locationLab.lineBreakMode = 0;
        self.locationLab.numberOfLines = 0;
        //竖分割线
        UIView * borderView = [[UIView alloc] init];
        borderView.backgroundColor = getColor(@"dfe1e4");
        [rectangleView addSubview:borderView];
        //电话
        self.phoneBtn = [[UIButton alloc] init];
        [self.phoneBtn setImage:[UIImage imageNamed:@"callPhone"] forState:UIControlStateNormal];
        [self.phoneBtn addTarget:self action:@selector(phoneBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [rectangleView addSubview:self.phoneBtn];
        //masonry
        __weak typeof (self)weakSelf = self;
        [locationImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(rectangleView.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.width.mas_offset(14/WIDTH_6_SCALE);
            make.height.mas_offset(19/WIDTH_6_SCALE);
            make.centerY.equalTo(rectangleView.mas_centerY);
        }];
        [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(locationImg.mas_right).mas_offset(14/WIDTH_6_SCALE);
            make.bottom.equalTo(locationImg.mas_centerY);
            make.top.lessThanOrEqualTo(rectangleView.mas_top).mas_offset(10/WIDTH_6_SCALE);
            make.right.equalTo(borderView.mas_right).mas_offset(-23/WIDTH_6_SCALE);
        }];
        [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.addressLab);
            make.top.equalTo(locationImg.mas_centerY);
            make.bottom.lessThanOrEqualTo(rectangleView.mas_bottom).mas_offset(-10/WIDTH_6_SCALE);
        }];
        [borderView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.phoneBtn.mas_left).mas_offset(-17/WIDTH_6_SCALE);
            make.top.equalTo(rectangleView.mas_top).mas_offset(29/WIDTH_6_SCALE);
            make.bottom.equalTo(rectangleView.mas_bottom).mas_offset(-29/WIDTH_6_SCALE);
            make.width.mas_offset(1/WIDTH_6_SCALE);
        }];
        [self.phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_offset(21/WIDTH_6_SCALE);
            make.centerY.equalTo(rectangleView.mas_centerY);
            make.right.equalTo(rectangleView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        }];
        [self setUpDataModule];//日期
    }return _headerView;
}
- (void)setUpDataModule{
    UIButton * dataBGView = [[UIButton alloc] initWithFrame:CGRectMake(0, self.rectangleView.bottom, SCREEN_WIDTH, 50/WIDTH_6_SCALE)];
    self.dataBGView = dataBGView;
    [dataBGView addTarget:self action:@selector(dataBGViewBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:dataBGView];
    [self setBorderWithView:dataBGView top:NO left:NO bottom:YES right:NO borderColor:getColor(@"f7f7f7") borderWidth:1];
    //今天日期
    NSDate *date = [NSDate date];
    NSDateFormatter *format1=[[NSDateFormatter alloc] init];
    NSTimeZone* timeZone =  [NSTimeZone timeZoneWithName:@"GMT+0800"];
    [format1 setTimeZone:timeZone];
    [format1 setDateFormat:@"yyyy-MM-dd"];
    self.todayString = [format1 stringFromDate:date];
    //明天日期
    NSDate *nextDay = [NSDate dateWithTimeInterval:24*60*60 sinceDate:date];//后一天
    self.nextdayString = [format1 stringFromDate:nextDay];
    //中间横线长度
    int middleLineW = 10/WIDTH_6_SCALE;
    //住店日期
    self.inHotelLab = [[UILabel alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, 0, SCREEN_WIDTH/4, dataBGView.height)];
    self.inHotelLab.text = self.todayString;
    self.inHotelLab.font = DEF_FontSize_14;
    self.inHotelLab.textAlignment = NSTextAlignmentRight;
    [dataBGView addSubview:self.inHotelLab];
    //中间横线
    UIView * middleLineView = [[UIView alloc] initWithFrame:CGRectMake(self.inHotelLab.right + 10/WIDTH_6_SCALE, dataBGView.height/2 - 1/WIDTH_6_SCALE, middleLineW, 2/WIDTH_6_SCALE)];
    middleLineView.backgroundColor = [UIColor grayColor];
    [dataBGView addSubview:middleLineView];
    //离店日期
    self.outHotelLab = [[UILabel alloc] initWithFrame:CGRectMake(middleLineView.right + 10/WIDTH_6_SCALE, 0, self.inHotelLab.width, self.inHotelLab.height)];
    self.outHotelLab.text = self.nextdayString;
    self.outHotelLab.font = DEF_FontSize_14;
    self.outHotelLab.textAlignment = NSTextAlignmentLeft;
    [dataBGView addSubview:self.outHotelLab];
    //共住几天
    self.totalDayLab = [[UILabel alloc] initWithFrame:CGRectMake(self.outHotelLab.right + 20/WIDTH_6_SCALE, 0, 80/WIDTH_6_SCALE, dataBGView.height)];
    self.totalDayLab.textAlignment = NSTextAlignmentLeft;
    self.totalDayLab.text = @"共1晚";
    self.totalDayLab.font = DEF_FontSize_12;
    [dataBGView addSubview:self.totalDayLab];
}
- (CDZStarsControl *)starsControl{
    if (!_starsControl) {
        _starsControl = [CDZStarsControl.alloc initWithFrame:CGRectMake(self.titleLab.left, self.titleLab.bottom + 8/WIDTH_6_SCALE, 80/WIDTH_6_SCALE , 20/WIDTH_6_SCALE) stars:5 starSize:CGSizeMake(13/WIDTH_6_SCALE, 15/WIDTH_6_SCALE) noramlStarImage:[UIImage imageNamed:@"unSelectStar"] highlightedStarImage:[UIImage imageNamed:@"selectStar"]];
        _starsControl.delegate = self;
        _starsControl.allowFraction = YES;
        _starsControl.score = 5.0f;
        [_starsControl setUserInteractionEnabled:NO];
    }return _starsControl;
}
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[].mutableCopy;
    }return _dataArray;
}
#pragma mark - UICollectionViewDelegate和UICollectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FeatureCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FeatureCollectionViewCell class]) forIndexPath:indexPath];
    if (indexPath.row % 3 == 0) {
        cell.bgView.layer.borderColor = [UIColor orangeColor].CGColor;
        cell.contentLab.textColor = [UIColor orangeColor];
    }else if (indexPath.row % 3 == 1){
        cell.bgView.layer.borderColor = getColor(@"005de9").CGColor;
        cell.contentLab.textColor = getColor(@"005de9");
    }else{
        cell.bgView.layer.borderColor = getColor(@"ea07b1").CGColor;
        cell.contentLab.textColor = getColor(@"ea07b1");
    }
    cell.contentLab.text = self.itemArr[indexPath.row];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.self.itemArr.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ComboViewController * vc = [[ComboViewController alloc] init];
    vc.prodeceID = [self.cellArr[indexPath.row] objectForKey:@"id"];
    vc.navigationItem.title = [self.cellArr[indexPath.row] objectForKey:@"goodsname"];
    if ([self.inHotelLab.text isEqualToString:@""] || self.inHotelLab.text == nil || [self.inHotelLab.text length] == 0) {
        vc.startTimeString = @"";
    }else{
        vc.startTimeString = self.inHotelLab.text;
    }
    if ([self.outHotelLab.text isEqualToString:@""] || self.outHotelLab.text == nil || [self.outHotelLab.text length] == 0) {
        vc.endTimeString = @"";
    }else{
        vc.endTimeString = self.outHotelLab.text;
    }
    if ([self.totalDayLab.text isEqualToString:@""] || self.totalDayLab.text == nil || [self.totalDayLab.text length] == 0) {
        vc.dayString = @"1";
    }else{
        vc.dayString = self.liveDaysString;
    }
//    if ([[self.cellArr[indexPath.row] objectForKey:@"ishotel"] isEqualToString:@"1"] && [[self.cellArr[indexPath.row] objectForKey:@"roomcount"] isEqualToString:@"0"]) {
//
//    }
    vc.isHotel = [self.cellArr[indexPath.row] objectForKey:@"ishotel"];
    vc.roomCount = [self.cellArr[indexPath.row] objectForKey:@"roomcount"];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - tableViewDelegate和tableViewDatasource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HotelTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([HotelTableViewCell class]) forIndexPath:indexPath];
    cell.model = self.cellArr[indexPath.row];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellArr.count;
}
#pragma mark - 单边边框
- (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width{
    if (top) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (left) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (bottom) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, view.frame.size.height - width, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (right) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(view.frame.size.width - width, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
}
#pragma mark - action
- (void)phoneBtnClick{
    [self callPhone:self.phoneNum];
}
- (void)shareBtnClick{
    [self.shareView showView];
}
//分享
- (void)wxShare:(int)scene{
    NSLog(@"微信分享");
    if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
        [self weChatShareURL:scene];
    }else {
        // 提示用户安装微信
        ShowMessage(@"请安装微信");
    }
}
//分享
- (void)weChatShareURL:(int)scene{
    //创建发送对象实例
    SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
    sendReq.bText = NO;//不使用文本信息
    sendReq.scene = scene;//0 = 好友列表 1 = 朋友圈 2 = 收藏
    //创建分享内容对象
    WXMediaMessage *urlMessage = [WXMediaMessage message];
    urlMessage.title = self.navigationItem.title;//分享标题
//    urlMessage.description = self.goodsDescribe;//分享描述
    [urlMessage setThumbImage:[UIImage imageNamed:@"martLogo"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
    //创建多媒体对象
    WXWebpageObject *webObj = [WXWebpageObject object];
    webObj.webpageUrl = [NSString stringWithFormat:@"%@?unionid=%@&typeid_goods=%@", self.shareURL, [UserModel sharedInstanced].userID, self.prodeceID];//分享链接
    //完成发送对象实例
    urlMessage.mediaObject = webObj;
    sendReq.message = urlMessage;
    //发送分享信息
    [WXApi sendReq:sendReq];
}
- (void)dataBGViewBtnClick{
    NSLog(@"日历");
    __weak typeof (self)weakSelf = self;
    self.chvc = [[CalendarHomeViewController alloc] init];
    [self mainViewClass:0];
    self.chvc.cleanArray = ^{
        [weakSelf.dataArray removeAllObjects];
    };
    self.chvc.calendarblock = ^(CalendarDayModel *model){
        NSLog(@"%@",[model toString]);
        if(model.style==CellDayTypeClick){
            [weakSelf.dataArray addObject:model.toString];
            NSSet *set = [NSSet setWithArray:weakSelf.dataArray];
            weakSelf.dataArray=[[set allObjects] mutableCopy];
            [weakSelf.dataArray sortUsingComparator:^NSComparisonResult(NSNumber *obj1, NSNumber *obj2) {
                return [obj1 compare:obj2];
            }];
        }else{
            [weakSelf.dataArray removeObject:model.toString];
        }
        [weakSelf mainViewClass:weakSelf.dataArray.count];
    };
    self.chvc.calendartitle = @"选择日期";
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:self.chvc];
    [self.chvc setHotelToDay:7 ToDateforString:nil];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}

- (void)mainViewClass:(NSInteger)num{
    [self.mainView removeFromSuperview];
    if (self.specificLab != nil) {
        [self.specificLab removeFromSuperview];
    }
    self.mainView=[[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - NAVI_HEIGHT - BOTTOM_HEIGHT - 50/WIDTH_6_SCALE,SCREEN_WIDTH, 50/WIDTH_6_SCALE)];
    self.mainView.backgroundColor=[UIColor grayColor];
    [self.chvc.view addSubview:self.mainView];
    
    UILabel * lable =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50/WIDTH_6_SCALE)];
    lable.font=[UIFont systemFontOfSize:14.0f];
    lable.textColor=[UIColor whiteColor];
    lable.textAlignment=NSTextAlignmentCenter;
    self.specificLab = lable;
    [self.mainView addSubview:lable];
    if(num==0){
        lable.text=@"请选择入住时间";
    }
    if(num==1){
        lable.text=@"请选择离店时间";
    }
    if(num==2){
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSDate* date1 = [formatter dateFromString:[self.dataArray objectAtIndex:0]];
        NSDate* date2 = [formatter dateFromString:[self.dataArray objectAtIndex:1]];
        NSLog(@"%@",date1);
        NSLog(@"%@",date2);
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *comps = [gregorian components:NSCalendarUnitDay fromDate:date1 toDate:date2  options:0];
        int days = [comps day];
        lable.text=[NSString stringWithFormat:@"%@入住---%@离店 共%d晚",[self.dataArray objectAtIndex:0],[self.dataArray objectAtIndex:1],days];
        self.chvc.getSpecificDate = ^{
            NSLog(@"住店日期：%@，离店日期%@，共%i天", [self.dataArray objectAtIndex:0],[self.dataArray objectAtIndex:1],days);
            self.inHotelLab.text = [self.dataArray objectAtIndex:0];
            self.outHotelLab.text = [self.dataArray objectAtIndex:1];
            self.totalDayLab.text = [NSString stringWithFormat:@"共%i天", days];
            self.liveDaysString = [NSString stringWithFormat:@"%i", days];
            [self getRoomCount];//上传日期
        };
        
    }
}
@end
